/**
 * 初始化Due
 */
import { mount } from "./mount.js";
import { constructProxy } from "./proxy.js"; //需要的代理模块

//给Due原型添加初始化方法，让index代码看情况干净整洁，思路明确
let uid = 0;
export function initMixin(Due) {
  Due.prototype._init = function (options) {
    const vm = this; //虚拟节点
    vm.uid = uid++;
    vm._isDue = true;
     //vue-data：
     if (options && options.data) {
      vm._data = constructProxy(vm, options.data, "");
    }
     //methods
     if (options && options.methods) {
      vm._methods = options.methods;
      //不用设置代理，可以直接挂载到原型上。
      for (const temp in options.methods) {
        if (Object.hasOwnProperty.call(options.methods, temp)) {
          const el = options.methods[temp];
          vm[temp] = el;
        }
      }
    }
    //computed
    if (options && options.computed) {
      vm._computed = options.computed; //跟vue-data差不多，匿了
    }

    //created
    if (options && options.created) {
      vm._created = options.created; //挂载到全局
    }

     //el
     if(options && options.el){
      let rootDom = document.querySelector(options.el);
      mount(vm,rootDom);
    } 
  };
}
